<?php
/**
 * Aes.php
 *
 * @author: cnx7 <zysafe@live.cn> 2019-07-29
 */

namespace common\domain\helper;

class Aes
{
    /**
     * 加密
     * @param $str
     * @return string
     */
    public static function encrypt($str)
    {
        $encrypt = openssl_encrypt($str, 'aes-256-cfb', KEY, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, IV);
        return base64_encode($encrypt);
    }

    /**
     * 解密
     * @param $str
     * @return string
     */
    public static function decrypt($str)
    {
        $decrypted = openssl_decrypt(base64_decode($str), 'aes-256-cfb', KEY, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, IV);
        return $decrypted;
    }

}
